﻿using Microsoft.Practices.Prism.Mvvm;
using Microsoft.Practices.Prism.PubSubEvents;
using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Navigation;

namespace Flashlight.Mvvm
{
    public sealed partial class App : MvvmAppBase
    {
        UnityContainer _container = new UnityContainer();
        IEventAggregator _eventAggregator = new EventAggregator();

        public App()
        {
            this.InitializeComponent();
        }

        protected override System.Threading.Tasks.Task OnInitializeAsync(IActivatedEventArgs args)
        {
            _container.RegisterInstance<IEventAggregator>(this._eventAggregator);
            _container.RegisterType<Services.ILightService, Services.LightService>(new ContainerControlledLifetimeManager());
            _container.RegisterType<Factories.ILightFactory, Factories.LightFactory>(new ContainerControlledLifetimeManager());
            return base.OnInitializeAsync(args);
        }

        protected override object Resolve(Type type)
        {
            return _container.Resolve(type);
        }

        protected override System.Threading.Tasks.Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
        {
            this.NavigationService.Navigate("Main", null);
            return Task.FromResult<object>(null);
        }
    }
}